// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    wx.cloud.init({
      env: 'study-9gbntrvm3c2dfbe4'
    })
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {

  },
  db(which){
    return wx.cloud.database().collection(which)
  },
  getList(which) {
    let db = wx.cloud.database().collection(which)
    return db.get()
  },
  removeOne(which, id) {
    return wx.cloud.database().collection(which).doc(id).remove()
  },
  getOne(which, id) {
    return wx.cloud.database().collection(which).doc(id).get()
  },
  navigateTo(url, loginJudgment = false) {
    if (wx.getStorageSync('userInfo') || !loginJudgment) {
      wx.navigateTo({
        url: url
      })
    } else {
      wx.showToast({
        title: "请先登录",
        icon: "none"
      })
    }
  }
})